using System;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Xml;
using System.Xml.Serialization;
using SubSonic;
using SubSonic.Utilities;

//Generated on 18/07/2007 15:55:01 by rupert_bates

namespace OpenProject.DataObjects{
    /// <summary>
    /// Strongly-typed collection for the CMSContent class.
    /// </summary>
    [Serializable]
    public partial class CMSContentCollection : ActiveList<CMSContent, CMSContentCollection> 
    {       
        public CMSContentCollection() {}

    }

    /// <summary>
    /// This is an ActiveRecord class which wraps the CMSContent table.
    /// </summary>
    [Serializable]
    public partial class CMSContent : ActiveRecord<CMSContent>
    {
    
	    #region Default Settings
	    protected static void SetSQLProps() 
	    {
		    GetTableSchema();
	    }

	    #endregion
        #region Schema Accessor
	    public static TableSchema.Table Schema
        {
            get
            {
                if (BaseSchema == null)
                {
                    SetSQLProps();
                }

                return BaseSchema;
            }

        }

    	
        private static void GetTableSchema() 
	    {
            if(!IsSchemaInitialized)
            {
                //Schema declaration
				TableSchema.Table schema = new TableSchema.Table("CMSContent", TableType.Table, DataService.GetInstance("OpenProject"));
                schema.Columns = new TableSchema.TableColumnCollection();
                schema.SchemaName = @"dbo";
                //columns
                
                TableSchema.TableColumn colvarContentID = new TableSchema.TableColumn(schema);
                colvarContentID.ColumnName = "ContentID";
                colvarContentID.DataType = DbType.Int32;
                colvarContentID.MaxLength = 0;
                colvarContentID.AutoIncrement = true;
                colvarContentID.IsNullable = false;
                colvarContentID.IsPrimaryKey = true;
                colvarContentID.IsForeignKey = false;
                colvarContentID.IsReadOnly = false;
                
                
                schema.Columns.Add(colvarContentID);
                
                TableSchema.TableColumn colvarContentGUID = new TableSchema.TableColumn(schema);
                colvarContentGUID.ColumnName = "ContentGUID";
                colvarContentGUID.DataType = DbType.Guid;
                colvarContentGUID.MaxLength = 0;
                colvarContentGUID.AutoIncrement = false;
                colvarContentGUID.IsNullable = false;
                colvarContentGUID.IsPrimaryKey = false;
                colvarContentGUID.IsForeignKey = false;
                colvarContentGUID.IsReadOnly = false;
                
						colvarContentGUID.DefaultSetting = @"(newid())";
				
                
                schema.Columns.Add(colvarContentGUID);
                
                TableSchema.TableColumn colvarTitle = new TableSchema.TableColumn(schema);
                colvarTitle.ColumnName = "Title";
                colvarTitle.DataType = DbType.String;
                colvarTitle.MaxLength = 500;
                colvarTitle.AutoIncrement = false;
                colvarTitle.IsNullable = true;
                colvarTitle.IsPrimaryKey = false;
                colvarTitle.IsForeignKey = false;
                colvarTitle.IsReadOnly = false;
                
                
                schema.Columns.Add(colvarTitle);
                
                TableSchema.TableColumn colvarContentName = new TableSchema.TableColumn(schema);
                colvarContentName.ColumnName = "ContentName";
                colvarContentName.DataType = DbType.String;
                colvarContentName.MaxLength = 50;
                colvarContentName.AutoIncrement = false;
                colvarContentName.IsNullable = false;
                colvarContentName.IsPrimaryKey = false;
                colvarContentName.IsForeignKey = false;
                colvarContentName.IsReadOnly = false;
                
                
                schema.Columns.Add(colvarContentName);
                
                TableSchema.TableColumn colvarBody = new TableSchema.TableColumn(schema);
                colvarBody.ColumnName = "Body";
                colvarBody.DataType = DbType.String;
                colvarBody.MaxLength = -1;
                colvarBody.AutoIncrement = false;
                colvarBody.IsNullable = true;
                colvarBody.IsPrimaryKey = false;
                colvarBody.IsForeignKey = false;
                colvarBody.IsReadOnly = false;
                
                
                schema.Columns.Add(colvarBody);
                
                TableSchema.TableColumn colvarLocale = new TableSchema.TableColumn(schema);
                colvarLocale.ColumnName = "Locale";
                colvarLocale.DataType = DbType.String;
                colvarLocale.MaxLength = 7;
                colvarLocale.AutoIncrement = false;
                colvarLocale.IsNullable = false;
                colvarLocale.IsPrimaryKey = false;
                colvarLocale.IsForeignKey = false;
                colvarLocale.IsReadOnly = false;
                
						colvarLocale.DefaultSetting = @"(N'en-US')";
				
                
                schema.Columns.Add(colvarLocale);
                
                TableSchema.TableColumn colvarCreatedOn = new TableSchema.TableColumn(schema);
                colvarCreatedOn.ColumnName = "CreatedOn";
                colvarCreatedOn.DataType = DbType.DateTime;
                colvarCreatedOn.MaxLength = 0;
                colvarCreatedOn.AutoIncrement = false;
                colvarCreatedOn.IsNullable = true;
                colvarCreatedOn.IsPrimaryKey = false;
                colvarCreatedOn.IsForeignKey = false;
                colvarCreatedOn.IsReadOnly = false;
                
						colvarCreatedOn.DefaultSetting = @"(getdate())";
				
                
                schema.Columns.Add(colvarCreatedOn);
                
                TableSchema.TableColumn colvarCreatedBy = new TableSchema.TableColumn(schema);
                colvarCreatedBy.ColumnName = "CreatedBy";
                colvarCreatedBy.DataType = DbType.String;
                colvarCreatedBy.MaxLength = 50;
                colvarCreatedBy.AutoIncrement = false;
                colvarCreatedBy.IsNullable = true;
                colvarCreatedBy.IsPrimaryKey = false;
                colvarCreatedBy.IsForeignKey = false;
                colvarCreatedBy.IsReadOnly = false;
                
                
                schema.Columns.Add(colvarCreatedBy);
                
                TableSchema.TableColumn colvarModifiedOn = new TableSchema.TableColumn(schema);
                colvarModifiedOn.ColumnName = "ModifiedOn";
                colvarModifiedOn.DataType = DbType.DateTime;
                colvarModifiedOn.MaxLength = 0;
                colvarModifiedOn.AutoIncrement = false;
                colvarModifiedOn.IsNullable = true;
                colvarModifiedOn.IsPrimaryKey = false;
                colvarModifiedOn.IsForeignKey = false;
                colvarModifiedOn.IsReadOnly = false;
                
						colvarModifiedOn.DefaultSetting = @"(getdate())";
				
                
                schema.Columns.Add(colvarModifiedOn);
                
                TableSchema.TableColumn colvarModifiedBy = new TableSchema.TableColumn(schema);
                colvarModifiedBy.ColumnName = "ModifiedBy";
                colvarModifiedBy.DataType = DbType.String;
                colvarModifiedBy.MaxLength = 50;
                colvarModifiedBy.AutoIncrement = false;
                colvarModifiedBy.IsNullable = true;
                colvarModifiedBy.IsPrimaryKey = false;
                colvarModifiedBy.IsForeignKey = false;
                colvarModifiedBy.IsReadOnly = false;
                
                
                schema.Columns.Add(colvarModifiedBy);
                
                BaseSchema = schema;
                //add this schema to the provider
                //so we can query it later
                DataService.Providers["OpenProject"].AddSchema("CMSContent",schema);
            }

        }

        #endregion
        
        #region Query Accessor
	    public static Query CreateQuery()
	    {
		    return new Query(Schema);
	    }

	    #endregion
	    
	    #region .ctors
	    public CMSContent()
	    {
            SetSQLProps();
            SetDefaults();
            MarkNew();
        }

        
        public CMSContent(bool useDatabaseDefaults)
	    {
		    SetSQLProps();
		    if(useDatabaseDefaults)
		    {
				ForceDefaults();
			}

			MarkNew();
	    }

	    public CMSContent(object keyID)
	    {
		    SetSQLProps();
            SetDefaults();
		    LoadByKey(keyID);
	    }

    	 
	    public CMSContent(string columnName, object columnValue)
        {
            SetSQLProps();
            SetDefaults();
            LoadByParam(columnName,columnValue);
        }

        
	    #endregion
	    
	    #region Props
	    
          
        [XmlAttribute("ContentID")]
        public int ContentID 
	    {
		    get { return GetColumnValue<int>("ContentID"); }

            set 
		    {
			    SetColumnValue("ContentID", value);
            }

        }

	      
        [XmlAttribute("ContentGUID")]
        public Guid ContentGUID 
	    {
		    get { return GetColumnValue<Guid>("ContentGUID"); }

            set 
		    {
			    SetColumnValue("ContentGUID", value);
            }

        }

	      
        [XmlAttribute("Title")]
        public string Title 
	    {
		    get { return GetColumnValue<string>("Title"); }

            set 
		    {
			    SetColumnValue("Title", value);
            }

        }

	      
        [XmlAttribute("ContentName")]
        public string ContentName 
	    {
		    get { return GetColumnValue<string>("ContentName"); }

            set 
		    {
			    SetColumnValue("ContentName", value);
            }

        }

	      
        [XmlAttribute("Body")]
        public string Body 
	    {
		    get { return GetColumnValue<string>("Body"); }

            set 
		    {
			    SetColumnValue("Body", value);
            }

        }

	      
        [XmlAttribute("Locale")]
        public string Locale 
	    {
		    get { return GetColumnValue<string>("Locale"); }

            set 
		    {
			    SetColumnValue("Locale", value);
            }

        }

	      
        [XmlAttribute("CreatedOn")]
        public DateTime? CreatedOn 
	    {
		    get { return GetColumnValue<DateTime?>("CreatedOn"); }

            set 
		    {
			    SetColumnValue("CreatedOn", value);
            }

        }

	      
        [XmlAttribute("CreatedBy")]
        public string CreatedBy 
	    {
		    get { return GetColumnValue<string>("CreatedBy"); }

            set 
		    {
			    SetColumnValue("CreatedBy", value);
            }

        }

	      
        [XmlAttribute("ModifiedOn")]
        public DateTime? ModifiedOn 
	    {
		    get { return GetColumnValue<DateTime?>("ModifiedOn"); }

            set 
		    {
			    SetColumnValue("ModifiedOn", value);
            }

        }

	      
        [XmlAttribute("ModifiedBy")]
        public string ModifiedBy 
	    {
		    get { return GetColumnValue<string>("ModifiedBy"); }

            set 
		    {
			    SetColumnValue("ModifiedBy", value);
            }

        }

	    
	    #endregion
	    
	    
	 	
			
	    
	    //no foreign key tables defined (0)
	    
	    
	    
	    //no ManyToMany tables defined (0)
	    
	    #region ObjectDataSource support
    	
    	
	    /// <summary>
	    /// Inserts a record, can be used with the Object Data Source
	    /// </summary>
	    public static void Insert(Guid varContentGUID,string varTitle,string varContentName,string varBody,string varLocale,DateTime? varCreatedOn,string varCreatedBy,DateTime? varModifiedOn,string varModifiedBy)
	    {
		    CMSContent item = new CMSContent();
		    
            item.ContentGUID = varContentGUID;
            
            item.Title = varTitle;
            
            item.ContentName = varContentName;
            
            item.Body = varBody;
            
            item.Locale = varLocale;
            
            item.CreatedOn = varCreatedOn;
            
            item.CreatedBy = varCreatedBy;
            
            item.ModifiedOn = varModifiedOn;
            
            item.ModifiedBy = varModifiedBy;
            
	    
		    if (System.Web.HttpContext.Current != null)
			    item.Save(System.Web.HttpContext.Current.User.Identity.Name);
		    else
			    item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
	    }

    	
	    /// <summary>
	    /// Updates a record, can be used with the Object Data Source
	    /// </summary>
	    public static void Update(int varContentID,Guid varContentGUID,string varTitle,string varContentName,string varBody,string varLocale,DateTime? varCreatedOn,string varCreatedBy,DateTime? varModifiedOn,string varModifiedBy)
	    {
		    CMSContent item = new CMSContent();
		    
                item.ContentID = varContentID;
				
                item.ContentGUID = varContentGUID;
				
                item.Title = varTitle;
				
                item.ContentName = varContentName;
				
                item.Body = varBody;
				
                item.Locale = varLocale;
				
                item.CreatedOn = varCreatedOn;
				
                item.CreatedBy = varCreatedBy;
				
                item.ModifiedOn = varModifiedOn;
				
                item.ModifiedBy = varModifiedBy;
				
		    item.IsNew = false;
		    if (System.Web.HttpContext.Current != null)
			    item.Save(System.Web.HttpContext.Current.User.Identity.Name);
		    else
			    item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
	    }

	    #endregion
	    #region Columns Struct
	    public struct Columns
	    {
		    
		    
            public static string ContentID = @"ContentID";
            
            public static string ContentGUID = @"ContentGUID";
            
            public static string Title = @"Title";
            
            public static string ContentName = @"ContentName";
            
            public static string Body = @"Body";
            
            public static string Locale = @"Locale";
            
            public static string CreatedOn = @"CreatedOn";
            
            public static string CreatedBy = @"CreatedBy";
            
            public static string ModifiedOn = @"ModifiedOn";
            
            public static string ModifiedBy = @"ModifiedBy";
            
	    }

	    #endregion
    }

}

